package com.example.demo.controller;

import com.example.demo.entity.User;
import com.example.demo.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

@Controller
public class LoginController {
    @Autowired
    private LoginService loginService;
    @RequestMapping("/login")
    public String Login(){
        return "login";
    }

    @RequestMapping("/loginCheck")
    @ResponseBody
    public Map findUserByIdAndPwd(String user_account, String password){
        Map<String, Integer> result = new HashMap<>();
        User user = loginService.selectUser(user_account,password);
        System.out.print(user_account);
        System.out.print(user);
        if (user == null){
            result.put("msg",0);
        }else {
            result.put("msg",1);
        }
        return result;
    }

    @RequestMapping("/index")
    public String LoginSuccess(){
        return "index";
    }
}
